"""
pymysql入门
"""
from pymysql import Connection

# 创建连接对象

conn = Connection(
    host="localhost",  # IP地址 本地
    port=3306,  # 端口号
    user="root",  # 用户名
    password="root",  # 密码
    database="test"  # 库
)

# 测试连接是否成功
# print(conn.get_server_info())

# 执行非查询sql
# 获取游标对象
cursor = conn.cursor()
# cursor.execute("create table test_pymysql(id int)")

# 执行查询语句
cursor.execute("select * from student")
# 获取执行的结果
results: tuple = cursor.fetchall()
for result in results:
    print(result)
# 关闭连接
conn.close()
